﻿using ServerFramework.Tool.Singleton;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace server.Core.DataBase
{



    public class MySqlConnect: Singleton<MySqlConnect>
    {
        private const int MaxPool = 1000;//最大连接数
        private const int MinPool = 5;//最小连接数
        private const bool Asyn_Process = true;//设置异步访问数据库
                                               //在单个连接上得到和管理多个、仅向前引用和只读的结果集(ADO.NET2.0)
        private const bool Mars = true;
        private const int Conn_Timeout = 15;//设置连接等待时间
        private const int Conn_Lifetime = 15;//设置连接的生命周期
        private string ConnString = "";//连接字符串
        private SqlConnection SqlDrConn = null;//连接对象

        public MySqlConnect()
        {
            ConnString=GetConnString();
            SqlDrConn=new SqlConnection(ConnString);
        }
        private string GetConnString()
        {
            return "server=localhost;"
        + "integratedsecurity=sspi;"
        + "database=pubs;"
        + "MaxPoolSize=" + MaxPool + ";"
        + "MinPoolSize=" + MinPool + ";"
        + "ConnectTimeout=" + Conn_Timeout + ";"
        + "ConnectionLifetime=" + Conn_Lifetime + ";"
        + "AsynchronousProcessing=" + Asyn_Process + ";";
            //+"MultipleActiveResultSets="+Mars+";";
            //+"MultipleActiveResultSets="+Mars+";";
        }

        public SqlConnection SqlConnection
        {
            get
            {
                return SqlDrConn;
            }
        }

        // "datasource=127.0.0.1;port=3306;Charset=gb2312;database=cs;user=root;pwd=root;Allow User Variables=True;Connect Timeout=30";
    }
}
